/****************************************************************************

	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010

    This file is part of Maxsi Installer.

    Maxsi Installer is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maxsi Installer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Maxsi Installer.  If not, see <http://www.gnu.org/licenses/>.

	*/ #include "MaxsiInstallerContributors.h" /*

	If you modify this file, please enter your name below and provide contact
	information in MaxsiEngineContributors.h. For more information please see
	MaxsiEngineContributors.h.
	
	Contributors to this file:

	- Jonas 'Sortie' Termansen
	- [your name here]

	MaxsiInstaller.exe
	The main installing technology utilized in the powerful Maxsi Distribution
	platform.

	UI.cpp
	The User Interface for MaxsiInstaller

****************************************************************************/

#include "MaxsiEngine.h"
#include "MaxsiDistributionLink.h"
#include "Main.h" 
#include "UI.h" 
#include "Thread.h"
#include "Data.h"

MaxsiInstallerPage::MaxsiInstallerPage()
{
	HeaderTextOverride	=	0;
}

bool MaxsiInstallerPage::InitializeForm(ME_Window* Parent)
{
	BaseClass::InitializeForm(Parent);

	HFONT hFont	=	CreateFont (13, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
						OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
						DEFAULT_PITCH | FF_SWISS, "Verdana");

	if ( HeaderTextOverride )
	{
		Header				=	CreateLabelAEx(WindowHWND,HeaderTextOverride,0,0,0,0,hFont);
	}
	else
	{
		char*	HeaderText	=	BuildString(3,"Welcome to the ",ProductName," Installer!");
		Header				=	CreateLabelAEx(WindowHWND,HeaderText,0,0,0,0,hFont);
		delete[] HeaderText;
	}

	return	true;
}

bool MaxsiInstallerPage::RenderForm(HWND hWnd)
{	
	if (!Initialized) { return false; }
    PAINTSTRUCT ps          = {0};
	HDC hDC = BeginPaint (hWnd, &ps);

	RECT rectClient;

    GetClientRect (hWnd, &rectClient);

	DrawSplitLine(hDC,50,rectClient.right);
	DrawSplitLine(hDC,rectClient.bottom-2.5*24,rectClient.right);
	
	EndPaint (hWnd, &ps);

	return true;
}

LRESULT MaxsiInstallerPage::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	return	BaseClass::WindowProc(hWnd,message,wParam,lParam);
}


bool MaxsiInstallerPage::TerminateForm()
{

	DestroyWindow(Header);


	return	BaseClass::TerminateForm();
}

bool MaxsiInstallerPage::NewResolution( WORD Width, WORD Height)
{	
	// TODO! Make this 'automatic' and move some of the code to reusable functions!

	// Invalidate Everything!
//	InvalidateRect(WindowHWND,NULL,TRUE);
	
//	ME_RedrawControl(Header	,WindowHWND,25,25,Width-25-25,24);

	MoveWindow(Header,25,25,Width-25-25,24,TRUE);

	RECT r;
	r.bottom=Height;
	r.top=0;
	r.left=0;
	r.right=Width;
	RedrawWindow(WindowHWND,&r,0, RDW_INVALIDATE | RDW_NOINTERNALPAINT | RDW_NOCHILDREN | RDW_ERASE);
	

	return true;
}

RECT MKRect(LONG Left, LONG Top, LONG Right, LONG Bottom)
{
	RECT	Result;

	Result.bottom	=	Bottom;
	Result.top		=	Top;
	Result.left		=	Left;
	Result.right	=	Right;

	return Result;
}